//
//  YMStatus.swift
//  YMWeiBo
//
//  Created by mimi on 16/7/23.
//  Copyright © 2016年 mimi. All rights reserved.
//

import UIKit

class YMStatus: NSObject {

    //        MARK: - 模型属性
    /// 创建时间
    var created_at: String?
    /// 微博ID
    var id: Int64 = 0
    /// 微博信息内容
    var text: String?
    /// 微博来源
    var source: String?
    //  用户数据
    var user: YMUser?
    //  转发微博
    var retweeted_status:YMStatus?
    //原厂配图
    var pic_urls:[YMPictureInfo]?
    
    // 转发数
    var reposts_count: Int = 0
    // 评论数
    var comments_count: Int = 0
    // 表态数
    var attitudes_count: Int = 0

    
    //KVC构造函数
    init(dic:[String:AnyObject]) {
        super.init()
        setValuesForKeysWithDictionary(dic)
    }
    
    //setValue
    override func setValue(value: AnyObject?, forKey key: String) {
       
        //如果key == "user"
        if key == "user" {
            guard let v = value as? [String:AnyObject] else{
                return
            }
            
            user = YMUser(dic: v)
        }else if key == "retweeted_status" {
            guard let v = value as? [String:AnyObject] else{
                return
            }
            
            retweeted_status = YMStatus(dic: v)
        }else if key == "pic_urls" {
            
            guard let v = value as? [[String:AnyObject]] else{
                return
            }
            
            //创建临时数组
            var temp:[YMPictureInfo] = [YMPictureInfo]()
            for dic in v{
                let picInfo:YMPictureInfo = YMPictureInfo(dic: dic)
                
                temp.append(picInfo)
                
            }
            pic_urls = temp
            
        }else{
            
            super.setValue(value, forKey: key)
        }
   
    }
    //没完全匹配是保证程序不会崩溃
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {
        
    }
    
}
